from flask import render_template,redirect,url_for,session
from flask_login import login_user, login_required, logout_user, current_user

#from dao.item import ItemDao 
#from model.item import Item
#from dao.picture import PictureDao
#from dao.category import CategoryDao
#from flask_babel import Babel, gettext

from controller import app

@app.route('/')
@app.route('/', methods=['GET','POST'])
def index():
    '''When a user logs in, their session is marked as 'fresh'.
    '''   
    if '_fresh' in session.keys() and session['_fresh']:
        '''
        # Prepare categories
        dao = CategoryDao()
        cats = dao.all()
        _categories = []
        for category in cats:
            _categories.append(category.name)
        '''
        return render_template('index.html', username=current_user.username)
    else:
        return render_template("index.html", username=None)




"""
@app.route("/settings")
@login_required
def settings():
    item_dao = ItemDao()
    items = item_dao.filter_by(Item.created, user_id=current_user.id)
    return render_template("setting.html", items=items, username=current_user.username)


@app.route("/manage_properties")
@login_required
def manage_properties():
    #item_dao = ItemDao()
    #items = item_dao.filter_by(Item.created, user_id=current_user.id)
    return render_template("manage_properties.html", properties=None, username=current_user.username)



@app.route("/pictures")
@login_required
def pictures():
    picture_dao = PictureDao()
    pics = picture_dao.filter_by(item_id=current_user.id)
    return render_template("pictures.html", pictures=pics)


@app.route("/testing")
@login_required
def testing():
    return render_template("testing.html")
"""